package com.tomecode.tools.maven.settings.model;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * contains informations required to a proxy settings.
 * 
 * @author Frastia Tomas
 * 
 */
public final class Proxy {

	private String id;
	/**
	 * Whether this proxy configuration is the active one.
	 */
	private String active;
	/**
	 * The proxy protocol.
	 */
	private String protocol;
	/**
	 * The proxy host.
	 */
	private String host;
	/**
	 * The proxy port
	 */
	private String port;
	/**
	 * The proxy user.
	 */
	private String username;
	/**
	 * The proxy password.
	 */
	private String password;
	/**
	 * The list of non-proxied hosts (delimited by |).
	 */
	private final List<String> nonProxyHosts;

	public Proxy() {
		nonProxyHosts = new ArrayList<String>();
	}

	public final String getId() {
		return id;
	}

	public final void setId(String id) {
		this.id = id;
	}

	public final String getActive() {
		return active;
	}

	public final boolean isActive() {
		return Boolean.parseBoolean(active);
	}

	public final void setActive(String active) {
		this.active = active;
	}

	public final String getProtocol() {
		return protocol;
	}

	public final void setProtocol(String protocol) {
		this.protocol = protocol;
	}

	public final String getHost() {
		return host;
	}

	public final void setHost(String host) {
		this.host = host;
	}

	public final String getPort() {
		return port;
	}

	public final void setPort(String port) {
		this.port = port;
	}

	public final String getUsername() {
		return username;
	}

	public final void setUsername(String username) {
		this.username = username;
	}

	public final String getPassword() {
		return password;
	}

	public final void setPassword(String password) {
		this.password = password;
	}

	public final String asNonProxyHosts() {
		String hosts = "";
		ListIterator<String> e = nonProxyHosts.listIterator();
		while (e.hasNext()) {
			hosts += e.next();
			if (e.hasNext()) {
				hosts += " | ";
			}
		}
		return hosts;
	}

	public final List<String> getNonProxyHosts() {
		return nonProxyHosts;
	}

	public final void setNonProxyHosts(List<String> nonProxyHosts) {
		this.nonProxyHosts.clear();
		this.nonProxyHosts.addAll(nonProxyHosts);
	}
}
